<%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%request.setCharacterEncoding("utf-8"); %>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld"%>
<%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld"%>
<c:if test="${not empty param.msg}">
	<script type="text/javascript" language="javascript">
		alert("${param.msg}");
		location.href="<c:url value='/Admin/Admin_Mctype.jsp' />";
	</script>
</c:if>
<c:if test="${mcTypeList==null && empty param.msg}">
	<c:redirect url="/Admin/McTypeManageServlet?fromPage=/Admin/Admin_Addtype.jsp"></c:redirect>
</c:if>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="pragma" content="no-cache" />
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
		<title>Shop 管理中心 - 类别管理</title>
		<link href="<c:url value='/Admin/styles/general.css' />" rel="stylesheet" type="text/css" />
		<link href="<c:url value='/Admin/styles/main.css' />" rel="stylesheet" type="text/css" />
		<script language="javascript">
			var array_0=new Array();
			<c:forEach var="mcTypeMap" items="${mcTypeList}" varStatus="mStatus">
		  	<c:forEach var="me" items="${mcTypeMap}" >
		  		<c:set var="maxType" value="${me.key}" />
		  		<c:set var="minList" value="${me.value}"/>
			</c:forEach>
				array_0[${mStatus.index}]="${maxType.sname}"
				var array_${maxType.nid}=new Array();
				<c:forEach var="minType" items="${minList}" varStatus="lStatus">
		            array_${maxType.nid}[${lStatus.index}]="${minType.nid}";
		      	</c:forEach>
			</c:forEach>
			
			function checkAddType() {
				var npid=document.getElementById('maxType');
				var arrayObj=eval("array_"+npid.value);
				var sname = document.getElementById('typename').value;
				var checkname= /[\u4e00-\u9fa5a-zA-Z0-9]+$/;
				if(sname.length==0) {
					alert('类别名不能为空');
					document.getElementById('typename').focus();
					return false;
				} else if(!checkname.test(sname)) {
					alert('类别名只能是汉字或英文字母或数字');
					document.getElementById('typename').focus();
					return false;
				}
				for(i=0;i<arrayObj.length;i++) {
					if(arrayObj[i]==sname) {
						alert('该类别名已存在,请更换后重新提交');
						document.getElementById('typename').focus();
						return false;
					}
				}
				return true;
			}
		</script>
	</head>
	<body>
		<h1>
			<span><a href="<c:url value='/Admin/Admin_Main.jsp ' />">Shop 类别管理</a> - 添加分类 </span>
		</h1>
		<div class="main-div1">
			<table width="100%" class="btable">
				<tr>
					<td>
					<form name="addType" action="<c:url value='/Admin/McTypeManageServlet' />" method="post" onSubmit="return checkAddType();"> 
					<input type="hidden" name="act" value="addType" />
					<input type="hidden" name="fromPage" value="/Admin/Admin_Addtype.jsp" />
						<table border="0" align="center" cellpadding="0" cellspacing="0" class="orderitemtable">
							<tr>
								<th>
									类别名称：
								</th>
								<td width="60%">
									<input type="text" name="typename" id="typename" />
								</td>
							</tr>
							<tr>
								<th>
									所属父类：
								</th>
								<td>
							        <select name="maxType" id="maxType" style="vertical-align:middle;width:147px;">
							        <option value="0">无父类别</option>
							        <c:forEach var="mcTypeMap" items="${mcTypeList}">
							        <c:forEach var="me" items="${mcTypeMap}">
							        <c:set var="maxType" value="${me.key}" />
							        <c:choose>
							        <c:when test="${typeMax==maxType.nid}">
							            <option value="${maxType.nid}" selected="selected">${maxType.sname}</option>
							        </c:when>
							        <c:otherwise>
							            <option value="${maxType.nid}">${maxType.sname}</option>
							        </c:otherwise>
							        </c:choose>
							        </c:forEach>
							        </c:forEach>
							        </select>
								</td>
							</tr>
							<tr>
								<td colspan="2" style="padding-left:40%;">
									<input type="submit" name="submit" value="提交" /> &nbsp;
									<input type="reset" name="reset" value="重置" />
								</td>
							</tr>
						</table>
					</form>
					</td>
				</tr>
			</table>
		</div>
		<div id="footer">
			版权所有 &copy;
		</div>
	</body>
</html>
